package com.clps.digital.controller;

import cn.hutool.core.util.ObjectUtil;
import com.clps.digital.common.BaseResponse;
import com.clps.digital.common.ErrorCode;
import com.clps.digital.common.ResultUtils;
import com.clps.digital.model.entity.Notification;
import com.clps.digital.service.NotificationService;

import java.util.List;

/**
 * @author: Chase
 * @date: 2024/9/3 10:13
 * @Version: 1.0
 * @description:
 */

public class NotificationController {

    private NotificationService notificationService;

    /**
     * 获取通知标题列表
     * @return
     */
    public BaseResponse<List<String>> getNotificationTitle() {
        List<String> notificationTitleList = notificationService.getNotificationTitle();
        if (ObjectUtil.isEmpty(notificationTitleList)) {
            return ResultUtils.error(ErrorCode.NOT_FOUND_ERROR, "获取通知标题失败");
        }
        return ResultUtils.success(notificationTitleList);
    }

    /**
     * 获取通知详情列表
     * @return
     */
    public BaseResponse<List<Notification>> getNotificationList() {
        List<Notification> notificationList = notificationService.getNotificationList();
        if (ObjectUtil.isEmpty(notificationList)) {
            return ResultUtils.error(ErrorCode.NOT_FOUND_ERROR, "获取通知失败");
        }
        return ResultUtils.success(notificationList);
    }

    /**
     * 获取单个通知详情
     * @param id
     * @return
     */
    public BaseResponse<Notification> getNotification(Long id) {
        Notification notification = notificationService.getNotification(id);
        if (ObjectUtil.isEmpty(notification)) {
            return ResultUtils.error(ErrorCode.NOT_FOUND_ERROR, "获取通知失败");
        }
        return ResultUtils.success(notification);
    }
}
